<!--
 * @Author: xuhy 1727317079@qq.com
 * @Date: 2022-09-04 09:48:48
 * @LastEditors: xuhy 1727317079@qq.com
 * @LastEditTime: 2022-09-04 21:27:31
 * @FilePath: \vue3_test\src\App.vue
 * @Description: 父组件
-->
<template>
  <h1>一个人的信息</h1>
  <h2>姓名: {{ name }}</h2>
  <h2>年龄: {{ age }}</h2>
  <h3>工作种类: {{ job.type }}</h3>
  <h3>工作薪水: {{ job.salary }}</h3>
  <button @click="changeInfo">修改个人信息</button>
</template>

<script>
import { ref } from "vue";
export default {
  name: "App",
  setup() {
    // 这样定义的数据不是响应式的
    /* let name = "张三";
    let age = 18; */

    // ref函数实现响应式, 依旧是通过Object.defineProperty()的get与set完成的
    let name = ref("张三");
    let age = ref(18);
    let job = ref({
      type: "前端工程师",
      salary: "30k",
    });
    function changeInfo() {
      name.value = "李四";
      age.value = 48;
      job.value.type = "UI设计师";
      job.value.salary = "60k";
      // console.log(name, age);
    }
    // 返回一个对象(常用)
    return {
      name,
      age,
      job,
      changeInfo,
    };
  },
};
</script>
